package cn.hchaojie.camp.day02.exercise;

import java.util.Arrays;

/**
 * 写一个方法，传入一个排好序整型数组，方法会将数组元素的顺序随机互换
 * 
 * @author hchaojie
 *
 */
public class ArrayReverse {
	public static void main(String[] args) {
		int[] numbers = {1, 2, 3, 4};
		int[] numbers2 = {4, 3, 2, 1};

		reverse(numbers);
		System.out.println(Arrays.toString(numbers));
		
		reverse(numbers2);
		System.out.println(Arrays.toString(numbers2));
	}

	public static void reverse(int[] numbers) {
		for (int i = 0, j = numbers.length - 1; i < numbers.length / 2; i++, j--) {
			int temp = numbers[i];
			numbers[i] = numbers[j];
			numbers[j] = temp;
		}
	}
}
